2015-09-22(胡工)修改版.sql 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpWageCommissionRecords]') AND type in (N'U'))
  2. begin
  3. CREATE TABLE [dbo].[tb_ErpWageCommissionRecords](
  4. [ID] [int] IDENTITY(1,1) NOT NULL,
  5. [Wcr_EmployeeID] [nvarchar](20) NULL,
  6. [Wcr_CommissionScheme] [nvarchar](25) NULL,
  7. [Wcr_CurrentPerformance] [decimal](18, 2) NULL,
  8. [Wcr_PieceCommission] [decimal](18, 2) NULL,
  9. [Wcr_CommissionWages] [decimal](18, 2) NULL,
  10. [Wcr_PerformanceTimeStart] [datetime] NULL,
  11. [Wcr_PerformanceTimeEnd] [datetime] NULL,
  12. [Wcr_CreateDateTime] [datetime] NULL,
  13. [Wcr_CreateName] [nvarchar](20) NULL,
  14. CONSTRAINT [PK_tb_ErpWageCommissionRecords] PRIMARY KEY CLUSTERED
  15. (
  16. [ID] ASC
  17. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  18. )
  19. end
  20. GO
  21. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ErpWageCommissionRecords')
  22. BEGIN
  23. DROP VIEW [dbo].Vw_ErpWageCommissionRecords
  24. END
  25. GO
  26. create View Vw_ErpWageCommissionRecords
  27. as
  28. SELECT ID
  29. ,Wcr_EmployeeID as 员工编号
  30. ,(select [User_Name] from tb_ErpUser where Wcr_EmployeeID=User_EmployeeID) as 员工姓名
  31. ,Wcr_CommissionScheme as 提成方案编号
  32. ,(select Sc_ClassName from tb_ErpSystemCategory where Wcr_CommissionScheme=Sc_ClassCode) as 提成方案名称
  33. ,Wcr_CurrentPerformance as 当前业绩
  34. ,Wcr_PieceCommission as 计件提成
  35. ,Wcr_CommissionWages as 提成工资
  36. ,Wcr_PerformanceTimeStart as 业绩开始时间
  37. ,Wcr_PerformanceTimeEnd as 业绩结束时间
  38. ,Wcr_CreateDateTime as 录入时间
  39. ,Wcr_CreateName as 录入人编号
  40. ,(select [User_Name] from tb_ErpUser where Wcr_CreateName=User_EmployeeID) as 录入人名称
  41. FROM tb_ErpWageCommissionRecords
  42. GO
  43. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_Customer_PaymentOrders')
  44. BEGIN
  45. DROP VIEW [dbo].Vw_Customer_PaymentOrders
  46. END
  47. GO
  48. create View Vw_Customer_PaymentOrders
  49. as
  50. select
  51. tb_ErpOrder.ID
  52. ,Ord_Number
  53. ,Ord_DividedShop
  54. ,Ord_Type
  55. ,Ord_OrderClass
  56. ,Ord_PhotographyCategory
  57. ,Ord_SeriesName
  58. ,Ord_SeriesPrice
  59. ,Ord_Class
  60. ,GP_OrderNumber
  61. ,GP_CustomerGroupID
  62. ,Cus_Name
  63. ,Cus_Name_py
  64. ,Cus_Telephone
  65. ,M_Cus_CustomerNumber
  66. ,(select stuff((select ','+ OrdPe_OrdersPerson from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPersonID
  67. ,(select stuff((select ','+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPerson
  68. ,Ord_CreateDatetime
  69. ,( SELECT count(id) FROM tb_ErpOrderProductList where OPlist_OrderNumber=Ord_Number and OPlist_PickupStatus=0) as PickupStatusCount
  70. ,Ord_SinceOrderNumber
  71. from tb_ErpOrder
  72. left join tempTB_AggregationCustomer on Ord_Number=GP_OrderNumber
  73. GO
  74. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_OrdersWagePaymentRecords')
  75. BEGIN
  76. DROP VIEW [dbo].Vw_OrdersWagePaymentRecords
  77. END
  78. GO
  79. create View Vw_OrdersWagePaymentRecords
  80. as
  81. SELECT
  82. tb_ErpPayment.ID,
  83. Pay_OrdNumber,
  84. Pay_AmountOf,
  85. Pay_OpenSingle,
  86. Pay_ThePayee,
  87. Pay_PaymentMethod,
  88. Pay_OrdersLocation,
  89. Pay_ReceivableProject,
  90. Pay_Remark,
  91. convert(varchar(10),Pay_CreateDatetime,120) as Pay_CreateDatetime,
  92. Pay_Category,
  93. Pay_TwoPinsCategory,
  94. dbo.fn_CheckUserIDGetUserName(Pay_OpenSingle) AS Pay_UserName,
  95. dbo.fn_CheckUserIDGetUserName(Pay_ThePayee) AS Pay_ThePayeeName,
  96. dbo.fn_GetClassCodeToName(Pay_PaymentMethod, Pay_PaymentMethod) AS Pay_PaymentMethodName,
  97. dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory) AS Pay_TwoPinsCategoryName,
  98. Pay_FinancialAuditdPeople,
  99. Pay_FinancialAudit,
  100. dbo.fn_CheckUserIDGetUserName(Pay_FinancialAuditdPeople)AS Pay_FinancialAuditdPeopleName,
  101. Pay_ShootingName,
  102. Pay_Type,
  103. Ord_DividedShop,
  104. Ord_Type,
  105. Cus_Name as Ord_CustomerName1,
  106. (select Tsorder_Name from Vw_TwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_Name,
  107. (select Tsorder_CustomerName from Vw_TwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_CustomerName,
  108. (select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) as Cus_Name,
  109. Ord_CreateDatetime,
  110. Ord_SeriesName,
  111. Ord_PhotographyCategory
  112. ,Ord_SinceOrderNumber
  113. FROM tb_ErpPayment
  114. left join Vw_Customer_PaymentOrders on Pay_OrdNumber=Ord_Number
  115. GO
  116. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ErpPieceCommissionRecords')
  117. BEGIN
  118. DROP VIEW [dbo].Vw_ErpPieceCommissionRecords
  119. END
  120. GO
  121. create View Vw_ErpPieceCommissionRecords
  122. as
  123. SELECT tb_ErpPieceCommissionRecords.ID
  124. ,Pcr_OrderNumber
  125. ,Pcr_DigitalDivision
  126. ,Pcr_Date
  127. ,Pcr_CompletionContents
  128. ,Pcr_Quantity
  129. ,Pcr_CreateTime
  130. ,Pcr_EntryPeople
  131. ,Pcr_Type
  132. ,(select [User_Name] from tb_ErpUser where Pcr_DigitalDivision=User_EmployeeID) as Pcr_DigitalDivisionName
  133. ,[dbo].[fn_GetClassCodeToName](Pcr_CompletionContents,Pcr_CompletionContents) as Pcr_CompletionContentsName
  134. ,(select [User_Name] from tb_ErpUser where Pcr_EntryPeople=User_EmployeeID) as Pcr_EntryPeopleName
  135. ,Ord_Type
  136. ,Ord_Class
  137. ,(select Cus_Name from tempTB_AggregationCustomer where Pcr_OrderNumber=GP_OrderNumber) as Cus_Name
  138. ,(select Cus_Telephone from tempTB_AggregationCustomer where Pcr_OrderNumber=GP_OrderNumber) as Cus_Telephone
  139. ,Ord_SeriesName
  140. ,Ord_SeriesPrice
  141. ,Pcr_Quantity*(select Wcs_Percentage from tb_ErpWageCommissionSet where Pcr_CompletionContents=Wcs_TypeCode) as 总价格
  142. ,Ord_SinceOrderNumber
  143. FROM tb_ErpPieceCommissionRecords
  144. left join tb_ErpOrder on tb_ErpPieceCommissionRecords.Pcr_OrderNumber=tb_ErpOrder.Ord_Number
  145. GO
  146. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_StaffPerformance_OrdersPerson')
  147. BEGIN
  148. DROP VIEW [dbo].Vw_StaffPerformance_OrdersPerson
  149. END
  150. GO
  151. create View Vw_StaffPerformance_OrdersPerson
  152. as
  153. SELECT
  154. tb_ErpPayment.ID
  155. ,Pay_OrdNumber as 订单号
  156. ,Pay_ShootingName as 拍摄阶段
  157. ,Pay_Category as 收款类别
  158. ,Pay_TwoPinsCategory as 二销类别编号
  159. ,dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory) AS 二销类别名称
  160. ,Pay_AmountOf as 收款金额
  161. ,Pay_OpenSingle as 接单人编号
  162. , dbo.fn_CheckUserIDGetUserName(Pay_OpenSingle) AS 接单人名称
  163. ,Pay_ThePayee as 收款人编号
  164. ,dbo.fn_CheckUserIDGetUserName(Pay_ThePayee) AS 收款人名称
  165. ,Pay_PaymentMethod as 付款方式编号
  166. ,dbo.fn_GetClassCodeToName(Pay_PaymentMethod, Pay_PaymentMethod) AS 付款方式名称
  167. ,Pay_OrdersLocation as 接单地点
  168. ,Pay_ReceivableProject as 收款项目
  169. ,Pay_FinancialAudit as 审核状态
  170. ,Pay_FinancialAuditdPeople as 审核人
  171. ,Pay_Remark as 备注
  172. ,Pay_CreateDatetime as 收款时间
  173. ,Pay_Type as 收款类型
  174. ,(case Pay_Type
  175. when 0 then (select Cus_Name from tempTB_AggregationCustomer where Pay_OrdNumber=GP_OrderNumber)
  176. when 1 then (select Tsorder_CustomerName from Vw_TwoSalesOrder where Pay_OrdNumber=Tsorder_Number)
  177. when 2 then (select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) else '' end) as '客户名称'
  178. ,(case Pay_Type
  179. when 0 then (select Ord_PhotographyCategory from tb_ErpOrder where Pay_OrdNumber=Ord_Number)else '' end) as '套系类别'
  180. ,(case Pay_Type
  181. when 0 then (select Ord_SeriesName from tb_ErpOrder where Pay_OrdNumber=Ord_Number)else '' end) as '套系名称'
  182. ,(case Pay_Type
  183. when 0 then (select Ord_OrderClass from tb_ErpOrder where Pay_OrdNumber=Ord_Number)else '' end) as '订单类别'
  184. ,(case Pay_Type
  185. when 0 then (select Ord_SeriesPrice from tb_ErpOrder where Pay_OrdNumber=Ord_Number)
  186. when 1 then (select Tsorder_Money from Vw_TwoSalesOrder where Pay_OrdNumber=Tsorder_Number)
  187. when 2 then (select Dsro_Amount from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) end) as '应收金额'
  188. ,(case Pay_Type
  189. when 0 then (dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory))
  190. when 1 then (dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory))
  191. when 2 then Pay_ReceivableProject end) as '项目名称'
  192. ,case when (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') is null then '0' else (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') end as '主门市比重'
  193. ,case when (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') is null then '0' else (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') end as '副门市比重'
  194. , ( case LEFT(Pay_OpenSingle,charindex(',',Pay_OpenSingle,1))
  195. when '' then Pay_OpenSingle
  196. else LEFT(Pay_OpenSingle,charindex(',',Pay_OpenSingle,1)-1) end)as '主门市'
  197. ,len(rtrim(ltrim(Pay_OpenSingle))) - len(rtrim(ltrim(replace(Pay_OpenSingle,',','')))) as '副门市个数'
  198. --, ( case Pay_Category
  199. -- when '后期收款' then ( len(rtrim(ltrim(Pay_OpenSingle))) - len(rtrim(ltrim(replace(Pay_OpenSingle,',','')))))
  200. -- else (select count(*) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Pay_OrdNumber and OrdPe_Type='1') end) as '副门市个数'
  201. ,(case (len(rtrim(ltrim(Pay_OpenSingle))) - len(rtrim(ltrim(replace(Pay_OpenSingle,',','')))))
  202. when 0 then Pay_AmountOf
  203. else cast(Pay_AmountOf * case when (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') is null then '0' else (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') end*0.01 as numeric(9,2))
  204. end) as '主门市金额'
  205. ,(case (len(rtrim(ltrim(Pay_OpenSingle))) - len(rtrim(ltrim(replace(Pay_OpenSingle,',','')))))
  206. when 0 then 0
  207. else cast(Pay_AmountOf * case when (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') is null then '0' else (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') end*0.01/(len(rtrim(ltrim(Pay_OpenSingle))) - len(rtrim(ltrim(replace(Pay_OpenSingle,',',''))))) as numeric(9,2))
  208. end) as '副门市金额'
  209. ,(select top 1 Ordpg_ViceNumber from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber) as 副订单号
  210. ,(case (select Ord_Type from tb_ErpOrder where Ord_Number=Pay_OrdNumber)
  211. when 0 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber)
  212. when 1 then (select Ordpg_PhotographyTime from tb_ErpOrdersPhotography where Ordpg_ViceNumber=(select top 1 Ordpg_ViceNumber from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber) )
  213. when 2 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber)
  214. else '' end) as 最后拍摄时间
  215. ,(case (select Ord_Type from tb_ErpOrder where Ord_Number=Pay_OrdNumber)
  216. when 0 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  217. when 1 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_ViceNumber=(select top 1 Ordpg_ViceNumber from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber) and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  218. when 2 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  219. else '' end) as 未拍个数
  220. ,(case (select Ord_Type from tb_ErpOrder where Ord_Number=Pay_OrdNumber)
  221. when 0 then (select Ordv_FilmSelectionStatus from tb_ErpOrderDigital where Ordv_Number=Pay_OrdNumber)
  222. when 1 then (select Ordv_FilmSelectionStatus from tb_ErpOrderDigital where Ordv_ViceNumber=(select top 1 Ordpg_ViceNumber from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber))
  223. when 2 then (select Ordv_FilmSelectionStatus from tb_ErpOrderDigital where Ordv_Number=Pay_OrdNumber)
  224. else '' end) as 选片状态
  225. ,(case (select Ord_Type from tb_ErpOrder where Ord_Number=Pay_OrdNumber)
  226. when 0 then (select Ordv_FilmSelectionTime from tb_ErpOrderDigital where Ordv_Number=Pay_OrdNumber)
  227. when 1 then (select Ordv_FilmSelectionTime from tb_ErpOrderDigital where Ordv_ViceNumber=(select top 1 Ordpg_ViceNumber from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber))
  228. when 2 then (select Ordv_FilmSelectionTime from tb_ErpOrderDigital where Ordv_Number=Pay_OrdNumber)
  229. else '' end) as 选片时间
  230. ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=(select top 1 Ordpg_ViceNumber from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber) and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态
  231. ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = (select top 1 Ordpg_ViceNumber from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber) and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期
  232. ,Ord_CustomerSource as 客户来源
  233. ,(select sum(Pay_AmountOf) from tb_ErpPayment where Ord_Number=Pay_OrdNumber and Pay_Category!='后期收款') as 前期实收金额
  234. ,Ord_SinceOrderNumber as 自定义订单号
  235. FROM tb_ErpPayment
  236. left join tb_ErpOrder on Pay_OrdNumber=Ord_Number
  237. GO
  238. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_StaffPerformance_Photograph')
  239. BEGIN
  240. DROP VIEW [dbo].Vw_StaffPerformance_Photograph
  241. END
  242. GO
  243. create View Vw_StaffPerformance_Photograph
  244. as
  245. SELECT
  246. Ordv_Number as 主订单
  247. ,Ordv_ViceNumber as 副订单
  248. ,(select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) as 订单类型
  249. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  250. when 0 then (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  251. when 1 then (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  252. when 2 then (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  253. else '' end) as 拍摄名称
  254. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  255. when 0 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number)
  256. when 1 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber)
  257. when 2 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number)
  258. else '' end) as 最后拍摄时间
  259. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  260. when 0 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  261. when 1 then (select count(id) as id from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  262. when 2 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  263. else '' end) as 未拍个数
  264. ,(case Ordv_FilmSelectionStatus when 1 then 'OK' else '未选' end) as 选片状态
  265. ,Ordv_FilmSelectionTime as 选片时间
  266. ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态
  267. ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期
  268. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  269. when 0 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and Ordpg_SightsLevel='BEBBBCADDEBFJDFFC')
  270. when 1 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_ViceNumber=Ordv_ViceNumber and Ordpg_SightsLevel='BEBBBCADDEBFJDFFC')
  271. when 2 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and Ordpg_SightsLevel='BEBBBCADDEBFJDFFC')
  272. else '' end) as '景点一级个数'
  273. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  274. when 0 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and Ordpg_SightsLevel='BEBBBCADEGBGAFFJC')
  275. when 1 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_ViceNumber=Ordv_ViceNumber and Ordpg_SightsLevel='BEBBBCADEGBGAFFJC')
  276. when 2 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and Ordpg_SightsLevel='BEBBBCADEGBGAFFJC')
  277. else '' end) as '景点二级个数'
  278. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  279. when 0 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and Ordpg_SightsLevel='BEBBBCADAFBHBCHCI')
  280. when 1 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_ViceNumber=Ordv_ViceNumber and Ordpg_SightsLevel='BEBBBCADAFBHBCHCI')
  281. when 2 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and Ordpg_SightsLevel='BEBBBCADAFBHBCHCI')
  282. else '' end) as '景点三级个数'
  283. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  284. when 0 then (select stuff((select ','+ Ordpg_Photographer from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  285. when 1 then (select stuff((select ','+ Ordpg_Photographer from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  286. when 2 then (select stuff((select ','+ Ordpg_Photographer from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  287. else '' end) as 主摄影师ID
  288. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  289. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  290. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  291. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  292. else '' end) as 主摄影师名称
  293. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  294. when 0 then (select stuff((select ','+ Ordpg_PhotographyAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  295. when 1 then (select stuff((select ','+ Ordpg_PhotographyAssistant from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  296. when 2 then (select stuff((select ','+ Ordpg_PhotographyAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  297. else '' end) as 摄影助理ID
  298. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  299. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_PhotographyAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  300. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_PhotographyAssistant) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  301. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_PhotographyAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  302. else '' end) as 摄影助理名称
  303. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  304. when 0 then (select stuff((select ','+ Ordpg_MakeupArtist from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  305. when 1 then (select stuff((select ','+ Ordpg_MakeupArtist from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  306. when 2 then (select stuff((select ','+ Ordpg_MakeupArtist from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  307. else '' end) as 主化妆ID
  308. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  309. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  310. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  311. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  312. else '' end) as 主化妆名称
  313. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  314. when 0 then (select stuff((select ','+ Ordpg_MakeupAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  315. when 1 then (select stuff((select ','+ Ordpg_MakeupAssistant from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  316. when 2 then (select stuff((select ','+ Ordpg_MakeupAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  317. else '' end) as 化妆助理ID
  318. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  319. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  320. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupAssistant) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  321. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  322. else '' end) as 化妆助理名称
  323. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  324. when 0 then (select stuff((select ','+ Ordpg_BootDivision from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  325. when 1 then (select stuff((select ','+ Ordpg_BootDivision from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  326. when 2 then (select stuff((select ','+ Ordpg_BootDivision from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  327. else '' end) as 引导师ID
  328. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  329. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  330. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  331. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  332. else '' end) as 引导师名称
  333. ,Ordv_EarlyRepairName as '初修师ID'
  334. ,dbo.fn_CheckUserIDGetUserName(Ordv_EarlyRepairName) as '初修师'
  335. ,Ordv_RefinementName as '精修师ID'
  336. ,dbo.fn_CheckUserIDGetUserName(Ordv_RefinementName) as '精修师'
  337. ,Ordv_DesignerName as '设计师ID'
  338. ,dbo.fn_CheckUserIDGetUserName(Ordv_DesignerName) as '设计师'
  339. ,Vw_StaffPerformance_OrdersPerson.ID
  340. ,订单号
  341. ,拍摄阶段
  342. ,收款类别
  343. ,二销类别编号
  344. ,二销类别名称
  345. ,收款金额
  346. ,接单人编号
  347. ,接单人名称
  348. ,收款人编号
  349. ,收款人名称
  350. ,付款方式编号
  351. ,付款方式名称
  352. ,接单地点
  353. ,收款项目
  354. ,审核状态
  355. ,审核人
  356. ,备注
  357. ,收款时间
  358. ,收款类型
  359. ,客户名称
  360. ,套系类别
  361. ,套系名称
  362. ,订单类别
  363. ,应收金额
  364. ,项目名称
  365. ,客户来源
  366. ,自定义订单号
  367. FROM tb_ErpOrderDigital
  368. left join Vw_StaffPerformance_OrdersPerson on Ordv_Number=订单号
  369. where 订单号 is not null
  370. GO